package com.deer.wms.base.system.web;

import com.deer.wms.base.system.model.DtMap;
import com.deer.wms.base.system.model.map.CarCoord;
import com.deer.wms.base.system.service.dtService;
import com.deer.wms.base.system.service.map.CarCoordService;
import com.deer.wms.base.system.util.ExcelReadUtil;
import com.deer.wms.common.core.controller.BaseController;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.io.IOException;
import java.util.List;
import java.util.Map;

/**
 * @author 李帅辰
 * @date 2021/1/20 9:29
 */

@Controller
@RequestMapping("/excel")
public class ExcelController extends BaseController {

    @Autowired
    private dtService Dt;

    @GetMapping("/ExcelDemo")
    @ResponseBody
    public void ExcelDemo() throws IOException {
        int fristIndex = 0;//初始化sheet索引
        int lastIndex = 20;//设置最大的sheet索引
        String path ="C:\\Users\\L_dy\\Desktop\\货位地图.xlsx";//解析的文件绝对路径


        CarCoord carCoord = new CarCoord();
        ExcelReadUtil excelReadUtil = new ExcelReadUtil();
        Map<String, List<String>> excelMap = excelReadUtil.read(fristIndex,lastIndex,path);

        List<String> cellList = excelMap.get("cellList");
        List<String> mapList = excelMap.get("mapList");
        //开始解析放入数据库
        for (String cellCode : cellList) {
                int indexOf = cellList.indexOf(cellCode);
                String map = mapList.get(indexOf);//地图信息
                String yNumBer = cellCode.substring(0, 2);
                String xNumber = cellCode.substring(3, 5);
                String zNumber = cellCode.substring(cellCode.length() - 2);
                int xPoint=0;
            if(xNumber.equals("25")){
                xPoint=0;
            }else if (xNumber.equals("24")){
                xPoint=1;
            }else if (xNumber.equals("23")){
                xPoint=2;
            }else if (xNumber.equals("22")){
                xPoint=3;
            }else if (xNumber.equals("21")){
                xPoint=4;
            }else if (xNumber.equals("20")){
                xPoint=5;
            }else if (xNumber.equals("19")){
                xPoint=6;
            }else if (xNumber.equals("18")){
                xPoint=7;
            }else if (xNumber.equals("17")){
                xPoint=8;
            }else if (xNumber.equals("16")){
                xPoint=9;
            }else if (xNumber.equals("15")){
                xPoint=10;
            }else if (xNumber.equals("14")){
                xPoint=11;
            }else if (xNumber.equals("13")){
                xPoint=12;
            }else if (xNumber.equals("12")){
                xPoint=13;
            }else if (xNumber.equals("11")){
                xPoint=14;
            }else if (xNumber.equals("10")){
                xPoint=15;
            }else if (xNumber.equals("09")){
                xPoint=16;
            }else if (xNumber.equals("08")){
                xPoint=17;
            }else if (xNumber.equals("07")){
                xPoint=18;
            }else if (xNumber.equals("06")){
                xPoint=19;
            }else if (xNumber.equals("05")){
                xPoint=20;
            }else if (xNumber.equals("04")){
                xPoint=21;
            }else if (xNumber.equals("03")){
                xPoint=22;
            }else if (xNumber.equals("02")){
                xPoint=23;
            }else if (xNumber.equals("01")){
                xPoint=24;
            }

                int yPoint= 0;
                if(yNumBer.equals("01")){
                    yPoint= 4;
                }else if(yNumBer.equals("02")){
                    yPoint=5;
                }else if(yNumBer.equals("03")){
                    yPoint=6;
                }else if(yNumBer.equals("04")){
                    yPoint=7;
                }else if(yNumBer.equals("05")){
                    yPoint=8;
                }else if(yNumBer.equals("06")){
                    yPoint=9;
                }else if(yNumBer.equals("07")){
                    yPoint=10;
                }else if(yNumBer.equals("08")){
                    yPoint=11;
                }else if(yNumBer.equals("09")){
                    yPoint=12;
                }else if(yNumBer.equals("10")){
                    yPoint=13;
                }else if(yNumBer.equals("11")){
                    yPoint=14;
                }else if(yNumBer.equals("12")){
                    yPoint=15;
                }else if(yNumBer.equals("13")){
                    yPoint=16;
                }


                String pointAttribute="";
                if(map.equals("下货")){
                    pointAttribute= "00100100";
                }else if(map.equals("上下货")){
                    pointAttribute="00101100";
                }else if(map.equals("右上下道")){
                    pointAttribute="00111101";
                }else if(map.equals("右左上下道")){
                    pointAttribute="00111111";
                }else if(map.equals("左上下道")){
                    pointAttribute="00111110";
                }else if(map.equals("上货")){
                    pointAttribute="00101000";
                }else if(map.equals("上下出入")){
                    pointAttribute="01111100";
                }else if(map.equals("上提")){
                    pointAttribute="01001000";
                }else if (map.equals("右上道")){
                    pointAttribute="00111001";
                }else if (map.equals("右左上道")){
                    pointAttribute="00111011";
                }else if (map.equals("右左道")){
                    pointAttribute="00110011";
                }else if (map.equals("B")){
                    pointAttribute="-1";
                }
                carCoord.setCellCode(cellCode);//地图编码
                carCoord.setyPoint(yPoint);//y轴
                carCoord.setxPoint(xPoint);
                carCoord.setFloor(Integer.parseInt(zNumber));//层数
                carCoord.setPointAttribute(pointAttribute);//坐标
                carCoord.setxLastPointDistance(1);
                 carCoord.setyLastPointDistance(1);
              Dt.saveCarCoord(carCoord);
        }
    }
}
